import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.util.Random;

public class generate_random_provider extends UnicastRemoteObject implements random_service {
	
	Random rand;
	
	public generate_random_provider() throws RemoteException {
		super();
		rand = new Random();
	}
	
	public String random(String s1, String s2) {
		String result = "TRUE";
		try {
			int lower = Integer.parseInt(s1);
			int higher = Integer.parseInt(s2);
			
			if(lower >= higher) { 
				System.err.printf("%d must be strictly less than %d\n", lower, higher);
				result = "FALSE";
			} else if(lower < -65535 || higher > 65536) {
				System.out.printf("%d and %d must be in the range (-2^16-1, 2^16)", lower, higher);
				result = "FALSE";
			} else {
				result = Integer.toString(rand.nextInt(higher - lower) + lower);
			}
		} catch (NumberFormatException e) {
			System.err.printf("%s and %s must both be integers\n", s1, s2);
			result = "FALSE";
		}
		return result;
	}
}
